package com.lufei4.chestnut.orbyun.Broad;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.blankj.utilcode.util.ToastUtils;
import com.lufei4.chestnut.Constans;
import com.lufei4.chestnut.R;
import com.lufei4.chestnut.network.BaseActivity;

import java.util.Observable;
import java.util.Observer;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: Chestnut
 * @Package: com.lufei4.chestnut.orbyun.Broad
 * @ClassName: MyBroadcastActivity2
 * @Description: java类作用描述
 * @Author: liushijiang 15833013864@163.com
 * @CreateDate: 2020/9/25 16:35
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/9/25 16:35
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class MyBroadcastActivity2 extends BaseActivity implements Observer {
    @BindView(R.id.button11)
    Button button11;
    @BindView(R.id.button12)
    Button button12;
    @BindView(R.id.button13)
    Button button13;
    @BindView(R.id.tv_msg)
    TextView tvMsg;

    @Override
    public int getLayoutId() {
        return R.layout.activity_bro2;
    }

    @Override
    public void initView() {
        //对于被观察者需要调用addObserver()方法，添加它的观察者到观察者列表中：
        ObservableObject.getInstance().addObserver(this);
    }

    /**
     * 注：对于LocalBroadcastManager方式发送的应用内广播，只能通过LocalBroadcastManager动态注册，不能静态注册
     */

    @OnClick({R.id.button11, R.id.button12, R.id.button13})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.button11:
                break;
            case R.id.button12:


                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("name", "钉钉");
                intent.putExtra("data", bundle);
                intent.setAction(Constans.Broad_Action);
                sendBroadcast(intent);
//                LocalBroadcastManager localBroadcastManager=LocalBroadcastManager.getInstance(this);
//                localBroadcastManager.sendBroadcast(intent);

                break;
            case R.id.button13:
                break;
        }
    }

    @Override
    public void update(Observable o, Object arg) {
        String s = arg.toString();
        ToastUtils.showShort(s);
    }
}
